import request from '@/utils/request.js';


// 注册接口
export const userRegisterService = (registerData) => {
  // 通过URLSearchParams传递参数
  const params = new URLSearchParams();
  for (const registerDataKey in registerData) {
    params.append(registerDataKey, registerData[registerDataKey]);
  }
  return request.post('/user/register', params);
};

// 登录接口
export const userLoginService = (loginData) => {
  // 通过URLSearchParams传递参数
  const params = new URLSearchParams();
  for (const loginDataKey in loginData) {
    params.append(loginDataKey, loginData[loginDataKey]);
  }
  return request.post('/user/login', params);
};

// 用户信息
export const userInfoService = () => {
  return request.get('/user/userInfo');
};

// 更新用户信息
export const updateUserInfoService = (newUserInfo) => {
  return request.put('/user/update', newUserInfo);
};

// 修改密码
export const updatePassword = (user, password) => {
  const params = new URLSearchParams();
  params.append('password', password);
  return request.put('/updatePassword', user, password);
};

// 上传头像
export const uploadAvatarService = (url) => {
  const params = new URLSearchParams();
  params.append('url', url);
  return request.patch('/user/uploadAvatar', params);
};
